package com.example.yuanboot.common.config.datasource;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import java.util.HashMap;
import java.util.Map;

/**
 * 动态数据源
 *
 * @author csp 2021-08-23
 */
public class DynamicDataSource extends AbstractRoutingDataSource {

    private static Map<Object, Object> dataSourceMap = new HashMap<>();

    @Override
    protected Object determineCurrentLookupKey() {
        return DataSourceHolder.getDataSourceKey();
    }

    public void putAll(Map<Object, Object> map) {
        DynamicDataSource.dataSourceMap.putAll(map);
    }

    public static boolean isExistDataSourceKey(String key) {
        return dataSourceMap.containsKey(key);
    }

}
